package com.shortlink.auth.controller;

import com.shortlink.auth.dto.req.UserLoginReqDTO;
import com.shortlink.auth.dto.resp.UserLoginRespDTO;
import com.shortlink.auth.service.AuthService;
import com.shortlink.common.base.Result;
import com.shortlink.common.base.Results;
import com.shortlink.common.user.UserInfoDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 权限控制层
 *
 * @author wp
 */
@RequiredArgsConstructor
@RestController
public class AuthController {
    private final AuthService authService;

    @PostMapping("/web-api/login")
    public Result<UserLoginRespDTO> login(@RequestBody UserLoginReqDTO userLoginReqDTO) {
        UserLoginRespDTO userLoginRespDTO = authService.login(userLoginReqDTO);
        return Results.success(userLoginRespDTO);
    }

    @DeleteMapping("/web-api/logout")
    public Result<Void> logout() {
        return Results.success();
    }

    @GetMapping("/api/auth")
    public Result<UserInfoDTO> auth(String token, String requestPath) {
        UserInfoDTO userInfoDTO = authService.auth(token, requestPath);
        return Results.success(userInfoDTO);
    }
}
